package com.masterclient.app.modules.shop.contract;

import com.eoner.baselib.presenter.ThrowableConsumer;
import com.eoner.baselibrary.bean.shop.DealerStockItemBean;
import com.eoner.baselib.utils.toast.ToastUtil;
import com.eoner.baselib.container.CommonBaseResponse;
import com.masterclient.app.httpservice.RetrofitUtil2;

import java.util.List;

import io.reactivex.functions.Consumer;

/**
 * @auther hjian
 * @date 2020/10/14.
 */
public class DealerStockPresenter extends DealerStockContract.Presenter {

    @Override
    public void stockListData(String product_id) {
        mRxManager.add(toSubscribe(RetrofitUtil2.getInstance().dealerStockList(product_id)
                , new Consumer<CommonBaseResponse<List<DealerStockItemBean>>>() {
                    @Override
                    public void accept(CommonBaseResponse<List<DealerStockItemBean>> listBean) throws Exception {
                        if (listBean.getCode() == 0){
                            mView.showStockData(listBean.getData());
                        }else {
                            ToastUtil.showToast(listBean.getMsg());
                        }
                    }
                }, new ThrowableConsumer(){
                    @Override
                    public void accept(Throwable o) throws Exception {
                        super.accept(o);
                        ToastUtil.showToast("网络异常，请重试");
                    }
                }));
    }

}
